﻿Imports System.Data.SqlClient
Public Class FrmKhaiThacKiemke
    Dim tbl As DataTable
    Dim dbAdapter As SqlDataAdapter
    Dim cmd As SqlCommand
    Dim tennhap As String
    
    Private Sub NapTinhTrang()
        If (ob_cnn.State = ConnectionState.Open) Then
            ob_cnn.Close()
        End If
        ob_cnn.Open()
        cmd = New SqlCommand(" select * from DMTinhTrang", ob_cnn)
        tbl = New DataTable()
        tbl.Load(cmd.ExecuteReader())
        ComboBoxTinhTrang.DisplayMember = "TenTinhTrang"
        ComboBoxTinhTrang.ValueMember = "MaTinhTrangID"
        ComboBoxTinhTrang.DataSource = tbl
        ob_cnn.Close()
    End Sub
    Private Sub FrmNhapKiemke_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        NapTinhTrang()
    End Sub
    Private Sub TimKiem()
        Dim TuNgay As String
        TuNgay = String.Format("{0:MM/dd/yyyy}", DateTimePicker1.Value)
        Dim DenNgay As String
        DenNgay = String.Format("{0:MM/dd/yyyy}", DateTimePicker2.Value)
        cmd = New SqlCommand("SELECT hskk.NgayNhapKho, hskk.NamThucHien, dmtlkk.TenTaiLieuKK, dmhskk.Tenloaihoso, dvhc.TenCapDVHC, thbq.ThoiHanBaoQuan, kho.TenKho, ke.TenKe, ngan.TenNgan, phong.TenPhong, tinhtrang.TenTinhTrang, huyen.T_Huyen, xa.TenXa, hskk.MahosoID, cctt.MahsmuonID " &
                                "FROM CCTT_HOSOKIEMKE_THONGKE cctt, HOSOKIEMKE hskk, DMTailieuKK dmtlkk, DMHosokiemke dmhskk, CAPDONVIHANHCHINH dvhc, DMThoiHanBaoQuan thbq, TENXA xa, TENHUYEN huyen, DMKho kho, DMKe ke, DMNgan ngan, DMPhong phong, DMTinhTrang tinhtrang " &
                                "WHERE cctt.SoHoSo = hskk.MahosoID AND hskk.CapDVHCID = dvhc.CapDVHCID and hskk.MaLoaiHSID = dmtlkk.MaTaiLieuKK AND hskk.TenQuyen = dmhskk.MaloaiID AND hskk.MaTinhTrangId = tinhtrang.MaTinhTrangID AND  hskk.MaDMThoiHanID = thbq.MaDMThoiHan And hskk.MaxaId = xa.MaXa And hskk.MaHuyenID = huyen.maH And hskk.MaKhoId = kho.maKhoID And hskk.MaKeId = ke.MaKeID AND hskk.MaPhongId = phong.MaPhongID and hskk.MaNganId = ngan.MaNganID " &
                                "AND cctt.Tinhtrangid = '" & ComboBoxTinhTrang.SelectedValue & "' " &
                                "AND hskk.NgayNhapKho >='" & TuNgay & "' " &
                                "AND hskk.NgayNhapKho <='" & DenNgay & "' ", ob_cnn)
        tbl = New DataTable()
        tbl.Load(cmd.ExecuteReader())
        DataGridView_hienthi.DataSource = tbl
        If tbl.Rows.Count = 0 Then
            MessageBox.Show("Không tìm thấy thông tin ! ")
        End If

    End Sub
    Private Sub ButtonTìmkiem_Click(sender As Object, e As EventArgs) Handles ButtonTìmkiem.Click
        If (ob_cnn.State = ConnectionState.Open) Then
            ob_cnn.Close()
        End If
        ob_cnn.Open()
        TimKiem()
        ob_cnn.Close()
    End Sub

    Private Sub ButtonThoat_Click(sender As Object, e As EventArgs) Handles ButtonThoat.Click
        Me.Close()
    End Sub

    Private Sub ButtonXuatExcel_Click(sender As Object, e As EventArgs) Handles ButtonXuatExcel.Click
        XuatExcel(DataGridView_hienthi, "ThongKeKiemKe")
    End Sub

    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint

    End Sub
End Class